<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
	<c:set var="ctx" value="${pageContext.request.contextPath}"/>
	<link rel="stylesheet" type="text/css" href="${ctx}/jquery-easyui-1.4.5/themes/material/easyui.css">
	<link rel="stylesheet" type="text/css" href="${ctx}/jquery-easyui-1.4.5/themes/icon.css">
	<link rel="stylesheet" type="text/css" href="${ctx}/ext/css/ext-all.css">

	<script type="text/javascript" src="${ctx}/ext/js/ext-all.js"></script>
	<script type="text/javascript" src="${ctx}/jquery-easyui-1.4.5/jquery.min.js"></script>
	<script type="text/javascript" src="${ctx}/jquery-easyui-1.4.5/jquery.easyui.min.js"></script>
	<script type="text/javascript" src="${ctx}/jquery-easyui-1.4.5/locale/easyui-lang-zh_CN.js"></script>

	<script type="text/javascript" src="${ctx}/js/commom.js"></script>
	<script type="text/javascript" src="${ctx}/js/blx.js"></script>
	<script type="text/javascript" src="${ctx}/js/login.js"></script>

	<script type="text/javascript" src="${ctx}/layer/layer.js"></script>
	<link rel="stylesheet" type="text/css" href="/css/style.css">
<title>校园微生活管理平台注册界面</title>
</head>
<script>

var code = ""; //在全局定义验证码   
//产生验证码  
function createCode(){     
     var codeLength = 4;//验证码的长度  
     var checkCode = document.getElementById("imgCode");   
     var random = new Array(0,1,2,3,4,5,6,7,8,9,'A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R',  
     'S','T','U','V','W','X','Y','Z','a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z');//随机数  
     for(var i = 0; i < codeLength; i++) {//循环操作  
        var index = Math.floor(Math.random()*62);//取得随机数的索引（0~61）  
        code += random[index];//根据索引取得随机数加到code上  
    }  
    checkCode.value = code;//把code值赋给验证码  
} 
	function submitRegisterForm() {
		var userName = document.getElementById("userName").value;
		var inputCode = document.getElementById("code").value;
		var inputPwd = document.getElementById("passWord").value;
		var inputPwdAgain = document.getElementById("passwordAgain").value;

		code = code.toUpperCase();
		inputCode = inputCode.toUpperCase();
		
		if(inputCode.length <= 0){
			$.messager.alert("提示", "请输入验证码！");
		}else if(inputCode != code){
			$.messager.alert("提示", "验证码错误！");
		}else if(userName.length <= 0){
			$.messager.alert("提示", "请输入用户名！");
		}else if(inputPwd.length <= 0){
			$.messager.alert("提示", "请输入密码！");
		}else if(inputPwdAgain.length <= 0){
			$.messager.alert("提示", "请输入验证密码！");
		}else if(inputPwd != inputPwdAgain){
			$.messager.alert("提示", "两次密码要一致！");
		}else if(/[^\x00-\xff]/g.test(inputPwd)){//验证密码是否含有汉字，虽然输入框的type为password，在键盘上敲不进汉字，但是可以通过复制汉字进去
			$.messager.alert("提示", "输入的密码不可以含有汉字！");
		}else{
			var formData = new FormData($('#registerForm')[0]);
			$.ajax({
				async : false,
				type : "POST",
				url : '${ctx}/manage/doRegister',
				data : formData,
				cache : false,
				contentType : false,
				processData : false,
				dataType : 'json',
				xhr : function() { // custom xhr
					myXhr = $.ajaxSettings.xhr();
					if (myXhr.upload) { // if upload property exists
						myXhr.upload.addEventListener('progress',
								progressHandlingFunction, false); // progressbar
					}
					return myXhr;

				},
				//Ajax events
				success : function(data) {
		               if(data.success == 0 )
		               {
		            	   fun_ret = true;
		            	 //墨绿深蓝风
		            	   layer.alert(data.msg, {
		            	     skin: 'layui-layer-molv' //样式类名
		            	     ,closeBtn: 0
		            	   }, function(){
		            		   window.location.href = "${ctx}/index";
		            	   });
		               }
		               else
		               {
		            	   top.Ext.Msg.alert("返回提示",data.msg);
		            	   alert("2");
		               }
		           },
				error : errorHandler = function(data) {
					$.messager.alert("错误提示", data.msg);
					alert("3");
					return false;
				}
			});
			
			/* 
			$('#registerForm').form('submit', {
				url : '${ctx}/manage/doRegister',
				dataType : 'json',
				success : function(result) {
					var json = $.parseJSON(result);
					if (json.success == 0) {
						alert("注册成功！去登录吧～");
						window.location.href = "${ctx}/manage/goLogin";
					} else if (json.success == 1) {
						alert("注册失败！请使用不同的用户名注册！！！");
						window.location.href = "${ctx}/manage/goRegister";
					} else {
						$.messager.alert("提示", json.msg);
						createCode();//刷新验证码  
						$('#input').val('');
					}
				}
			}); */
			
		}
	}
	function clearForm() {
		$('#registerForm').form('clear');
	}
	function goLogin() {
		window.location.href = "${ctx}/index";
	}
	function changeImg(){
		alert("随便填一个就行啦～");
	}
	function btnSave_click() {
		var fun_ret;
		var vals = $('#formModule').serialize();
		var url = '${saveUrl}';
		var formData = new FormData($('#formModule')[0]);
		$.ajax({
			async : false,
			type : "POST",
			url : url,
			data : formData,
			cache : false,
			contentType : false,
			processData : false,
			dataType : 'json',
			xhr : function() { // custom xhr
				myXhr = $.ajaxSettings.xhr();
				if (myXhr.upload) { // if upload property exists
					myXhr.upload.addEventListener('progress',
							progressHandlingFunction, false); // progressbar
				}
				return myXhr;
			},
			//Ajax events
			success : function(data) {
	               if(data.success == 0 )
	               {
	            	   fun_ret = true;
	               }
	               else
	               {
	            	   top.Ext.Msg.alert("返回提示",data.msg);
	               }
	           },
			error : errorHandler = function(data) {
				$.messager.alert("错误提示", data.msg);
				return false;
			}
		});
		return fun_ret;
}

function progressHandlingFunction(e) {
	if (e.lengthComputable) {
		$('progress').attr({
			value : e.loaded,
			max : e.total
		});
	}
}
</script>
<body bgcolor="#fff" onload="createCode()"><!-- bgcolor="#E6E6FA" -->
	<!-- 注册窗口 -->
	<div id="registerDiv" class="easyui-window" title="校园微生活管理平台注册" resizable="false" closable="false" minimizable="false" maximizable="false" collapsible="false" data-options="iconCls:'icon-save'" style="width:100%;height:600px;padding:3px;background:#E1E1E1">
		<div style="padding:10px 10px 10px 10px" align="left">
			<a href="javascript:void(0)" class="easyui-linkbutton" data-options="iconCls:'icon-back'" style="width: 90px;height: 25px"  onclick="goLogin()">返回登录</a>
		</div>
		<div align="center">
			<img src="${ctx}/images/icon_school.png" width=100% height="260" style="background-repeat: no-repeat">
		</div>
		<br>
		<div style="padding:1px 0px 5px 20px" align="center">
	    	<form id="registerForm" method="post" >
	    		<table cellpadding="3" border="0">
	    			<tr height="30">
	    				<td>&nbsp;&nbsp;&nbsp;用户名:&nbsp;&nbsp;&nbsp;</td>
	    				<td><input class="easyui-validatebox textbox" type="text" id="userName" name="userName" data-options="required:true" maxlength="15" style="width: 160px;height: 25px"></input></td>
	    			</tr>
	    			<tr height="30">
	    				<td>&nbsp;手&nbsp;&nbsp;机&nbsp;&nbsp;号&nbsp;&nbsp;码:&nbsp;&nbsp;</td>
	    				<td><input class="easyui-validatebox textbox" id="telephone" type="text" value="" name="telephone" data-options="required:true" maxlength="16" style="width: 160px;height: 25px"></input></td>
	    			</tr>
	    			<tr height="30">
	    				<td>&nbsp;&nbsp;&nbsp;密&nbsp;&nbsp;&nbsp;码:&nbsp;&nbsp;&nbsp;</td>
	    				<td><input class="easyui-validatebox textbox" id="passWord" type="password" value="" name="passWord" data-options="required:true" maxlength="16" style="width: 160px;height: 25px"></input></td>
	    			</tr>
	    			<tr height="30">
	    				<td>&nbsp;确认密码：</td>
	    				<td><input class="easyui-validatebox textbox" id="passwordAgain" type="password" value="" name="passwordAgain" data-options="required:true" maxlength="16" style="width: 160px;height: 25px"></input></td>
	    			</tr>
	    			<tr height="30">
	    				<td>&nbsp;&nbsp;&nbsp;学&nbsp;&nbsp;&nbsp;校:&nbsp;&nbsp;&nbsp;</td>
	    				<td><select id="school" class="easyui-combobox" name="school" style="width:162px;">
    							<option value="闽江学院">闽江学院</option>
    							<option value="江夏学院">江夏学院</option>
    							<option value="福州大学">福州大学</option>
    							<option value="福建师范大学">福建师范大学</option>
    							<option value="福建医科大学">福建医科大学</option>
							</select>
						</td>
	    			</tr>
	    			<tr height="30">
	    				<td>&nbsp;&nbsp;&nbsp;验证码:&nbsp;&nbsp;&nbsp;</td>
	    				<td><input type="button" style="width: 70px; height: 25px" id="imgCode" onclick="createCode()" />
							<input class="easyui-validatebox textbox" type="text" id="code" name="code" data-options="required:true" style="width:80px;height: 25px;margin-left:2px;vertical-align:middle"></input>
						</td>
	    			</tr>
	    		</table>
	    	</form>
	    	<br>
	    	<div style="text-align:center;padding:2px">
	    		<a href="javascript:void(0)" class="easyui-linkbutton" style="width: 90px;height: 25px"  onclick="submitRegisterForm()">&nbsp;注&nbsp;册&nbsp;</a>
	    		<a href="javascript:void(0)" class="easyui-linkbutton" style="width: 90px;height: 25px"  onclick="clearForm()">&nbsp;清&nbsp;除&nbsp;</a>    	
	    	</div>
	    </div>
	</div>
	
	
</body>
</html>